<template>
  <div class="preview-contract">
    <div class="img imgPreview">
      <div class="preview">
        <!-- <a-skeleton v-if="iframeloading" /> -->
        <iframe
          frameborder="0"
          @load="loading"
          id="previewPdf"
          :src="pdfBaseUrl + 'file=' + picUrl"
          height="1200"
          width="100%"
        >
        </iframe>
      </div>
    </div>
    <div class="button">
      <a-space>
        <a-button @click="toBack">返回修改</a-button>
        <a-button type="primary" @click="toGeneratedContract"
          >确认生成合同</a-button
        >
      </a-space>
    </div>
  </div>
</template>
<script>
import { sellerGenerateContract, buyerGenerateContract } from "@/api/contract";
import { getCurIdentity } from "@/util/common";
import globalSite from "@/config/globalSite";

export default {
  props: {
    datas: {
      type: Array,
      default: () => {
        return [];
      }
    },
    imgFileList: {
      type: Array,
      default: () => {
        return [];
      }
    },
    pages: {
      type: String,
      default: ""
    }
  },
  components: {},
  data() {
    return {
      activeKey: 1,
      picUrl: "",
      fileId: ""
      // iframeloading :true,
    };
  },
  watch: {},
  computed: {
    identity() {
      return getCurIdentity(); //1买家，2卖家
    },
    pdfBaseUrl() {
      return globalSite.pdfBaseUrl;
    }
  },

  created() {
    this.initData();
  },
  methods: {
    loading() {
      // this.iframeloading = false
      // console.log(this.iframeloading )
    },
    initData() {
      let temporaryFile = this.datas[0].temporaryFile;
      this.fileId = temporaryFile.id;
      this.picUrl = temporaryFile ? temporaryFile.fileUrl : "";
      this.activeKey = this.datas[0].id;
    },
    //返回上一步
    toBack() {
      this.$emit("onStepChange", 1);
    },
    //生成合同
    toGeneratedContract() {
      switch (this.pages) {
        case "contractPage": //订单列表-生成合同
          this.contractPageToGeneratedContract();
      }
    },
    contractPageToGeneratedContract() {
      let parmas = {
        fileId: this.fileId,
        contractKey: this.datas[0].contractKey
      };
      let requesFun;
      this.identity === 1
        ? (requesFun = buyerGenerateContract)
        : (requesFun = sellerGenerateContract);
      requesFun(parmas)
        .then(res => {
          //跳转成功页面
          this.$emit("onStepChange", 3, [res]);
          this.$message.success("操作成功");
        })
        .finally(() => {});
    }
  }
};
</script>

<style lang="scss" scoped>
.preview-contract {
  background: #fff;
  margin-top: 20px;
  padding: 30px;
  .imgTabs {
    text-align: left;
    margin-bottom: 20px;
  }
  .imgPreview {
    margin-bottom: 20px;
  }
  .img,
  .button {
    text-align: center;
  }
}
</style>
